from mido import MidiFile
from pyo import *
import pyo.lib.tables
from musicpy import *


def play(s, c):
    write(c, name='temp.mid')
    mid = MidiFile(r"temp.mid")
    for message in mid.play():
        s.addMidiEvent(*message.bytes())


a = C('Dmaj7') % (1/4, 1/4) | C('Cmaj7') | C('Fadd9', 3) | C('D#maj7', 4) | (C('Dmaj7', 3)/-2) % (3/4,)
b = chord(['F#5', 'G5', 'A5', 'B5', 'G5'], 1/8, 1/8)
c = a & b

d0 = read(r'B:\muse\MuseScore\2103_05_melody.mid').tracks[0]
d1 = read(r'B:\muse\MuseScore\2103_05_melody_02.mid').tracks[0]
d2 = read(r'B:\muse\MuseScore\2103_05_chords.mid').tracks[0]

s = Server().boot().start()
mid = Notein()
osc = Osc(pyo.lib.tables.SquareTable(), freq=MToF(mid["pitch"]), mul=MidiAdsr(mid["velocity"])).mix(1)
rev = STRev(osc, revtime=1, cutoff=1000, bal=0.2).out()

play(s, (d0 | d1) & d2)
